class Solution {
public:
    int minNumberOfFrogs(string croakOfFrogs) {
        string str="croak";
        int hash[5]; //哈希表
        unordered_map<char,int> index;

        for(int i=0;i<str.size();i++)
        {
            index[str[i]]=i;
        }

        for(auto e:croakOfFrogs)
        {
            if(e=='c')
            {
                if(hash[index['k']]>0)
                {
                    hash[index['k']]--;
                    hash[index['c']]++;
                }
                else
                {
                    hash[index['c']]++;
                }
            }
            else
            {
                if(hash[index[e]-1]==0)return -1;
                hash[index[e]-1]--;
                hash[index[e]]++;
            }
        }
        
        for(int i=0;i<4;i++)
        {
            if(hash[i]>0)
            return -1;
        }

        return hash[4];
    }
};